import axios from "axios";
import {urlConfig} from "../Config";
import {userController} from "./UserController";

const fetchTicketsInfoForNo = async (noId: any) => {
  const msg = await axios.get(urlConfig.getUrlFor("/ticket",{noId}));
  return msg.data;
};

const buyTicket = async (noId: any, id: any, passenger: any) => {
  if (userController.isLogged()){
    await axios.post(urlConfig.getUrlFor("/ticket", {
      noId,id,passenger,account: userController.getUserInfo()?.account
    }));
  }
}

const fetchTicketsForUser = async () => {
  if (userController.isLogged()){
    const msg = await axios.get(urlConfig.getUrlFor("/ticket",
        {account: userController.getUserInfo()?.account}));
    return msg.data;
  }
  return null;
}

const rmTicket = async (id: any)=>{
  await axios.delete(urlConfig.getUrlFor("/ticket/"+id, {
    account: userController.getUserInfo()?.account
  }));
}

export {fetchTicketsInfoForNo, buyTicket, fetchTicketsForUser, rmTicket};